/**
 * fSpy
 * Copyright (c) 2020 - Per Gantelius
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import * as React from 'react'
import { ReferenceDistanceUnit } from '../../types/calibration-settings'
import Dropdown from '../common/dropdown'

interface ReferenceDistanceUnitDropdownProps {
  disabled?: boolean
  selectedUnit: ReferenceDistanceUnit
  onChange(unit: ReferenceDistanceUnit): void
}

const options = [
  {
    value: ReferenceDistanceUnit.None,
    id: ReferenceDistanceUnit.None,
    title: ReferenceDistanceUnit.None
  },
  {
    value: ReferenceDistanceUnit.Millimeters,
    id: ReferenceDistanceUnit.Millimeters,
    title: ReferenceDistanceUnit.Millimeters
  },
  {
    value: ReferenceDistanceUnit.Centimeters,
    id: ReferenceDistanceUnit.Centimeters,
    title: ReferenceDistanceUnit.Centimeters
  },
  {
    value: ReferenceDistanceUnit.Meters,
    id: ReferenceDistanceUnit.Meters,
    title: ReferenceDistanceUnit.Meters
  },
  {
    value: ReferenceDistanceUnit.Kilometers,
    id: ReferenceDistanceUnit.Kilometers,
    title: ReferenceDistanceUnit.Kilometers
  },
  {
    value: ReferenceDistanceUnit.Inches,
    id: ReferenceDistanceUnit.Inches,
    title: ReferenceDistanceUnit.Inches
  },
  {
    value: ReferenceDistanceUnit.Feet,
    id: ReferenceDistanceUnit.Feet,
    title: ReferenceDistanceUnit.Feet
  },
  {
    value: ReferenceDistanceUnit.Miles,
    id: ReferenceDistanceUnit.Miles,
    title: ReferenceDistanceUnit.Miles
  }
]

export default function ReferenceDistanceUnitDropdown(props: ReferenceDistanceUnitDropdownProps) {
  return (
    <Dropdown
      disabled={props.disabled}
      options={
        options
      }
      selectedOptionId={
        props.selectedUnit
      }
      onOptionSelected={(unit: ReferenceDistanceUnit) => {
        props.onChange(unit)
      }}
    />
  )
}
